# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Kr1ss $(echo \<kr1ss+x-yandex+com\>|sed s/\+/./g\;s/\-/@/)
# Contributor: ccorn

pkgname=git-delta
_pkgname=delta
pkgver=0.15.1
pkgrel=2
pkgdesc='Syntax-highlighting pager for git and diff output'
arch=('loong64' 'x86_64')
url='https://github.com/dandavison/delta'
license=('MIT')
depends=('libgit2.so')
makedepends=('cargo' 'mdbook')
checkdepends=('git')
source=("$pkgname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz")
sha512sums=('646244299ec79d59ff91fd0b2d9600795a6c0e4f3f6efa6629217a6847d6b736ceed45bd52435aeb25cd80ffa9630bf9cebce35312fead3de2bb5b0d04e790c4')
b2sums=('b29972e8fb1e640ced5f8148610a17177e08cda2988189bd3cad585937c85b8b749cf3e3fd4648599462b4272d4f3b99448cead13a688289732106e744a294d5')

prepare() {
  cd "$_pkgname-$pkgver"

  # download dependencies
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$_pkgname-$pkgver"

  # https://archlinux.org/todo/lto-fat-objects/
  CFLAGS+=' -ffat-lto-objects'

  # binary
  cargo build --frozen --release --all-features

  # html manual
  cd manual
  mdbook build --dest-dir html
}

check() {
  cd "$_pkgname-$pkgver"
  # some tests hang for 60+ seconds, find out why
  # took my machine ~ 470 seconds
  cargo test --frozen --all-features
}

package() {
  cd "$_pkgname-$pkgver"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" target/release/delta

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE

  # shell auto-completions
  install -vDm644 etc/completion/completion.bash \
    "$pkgdir/usr/share/bash-completion/completions/$_pkgname"
  install -vDm644 etc/completion/completion.zsh \
    "$pkgdir/usr/share/zsh/site-functions/_$_pkgname"
  install -vDm644 etc/completion/completion.fish \
    "$pkgdir/usr/share/fish/vendor_completions.d/$_pkgname.fish"

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # html manual
  cp -r manual/html "$pkgdir/usr/share/doc/$pkgname"
}
